/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.db;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.User;

/**
 *
 * @author user
 */
public class UsersDB extends DB {

    public User find(int id) {
        User user = null;
        
        try {
            rs = statement.executeQuery("SELECT * from user WHERE id=" + id);
            if (rs.next()) {
                int userId = Integer.parseInt(rs.getString("id"));
                user = new User(userId, rs.getString("username"), rs.getString("role"));
                user.maxNumberRoom = Integer.parseInt(rs.getString("max_number_room"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(UsersDB.class.getName()).log(Level.SEVERE, null, ex);
        }

        return user;
    }

    public User find(String username) {
        User user = null;

        try {
            rs = statement.executeQuery("SELECT * from user WHERE username='" + username + "'");
            if (rs.next()) {
                int userId = Integer.parseInt(rs.getString("id"));
                user = new User(userId, rs.getString("username"), rs.getString("role"));
                user.maxNumberRoom = Integer.parseInt(rs.getString("max_number_room"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(UsersDB.class.getName()).log(Level.SEVERE, null, ex);
        }

        return user;
    }
}
